﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;

namespace lcs.Web.Admin
{
    public class BasePage : System.Web.UI.Page
    {
        public BasePage(): base()
        {

        }
        public string DecodeDog(string str,string dogid)
        {
            if (isindog())
                return str;
            if (dogid == "")
                return EncodeString.EncodeBase64(str, false);
            else
            {
                if (dogid != getdogid())
                    return EncodeString.EncodeBase64(str, false);
                else
                    return str;
            }

        }
        public bool isallowproject(string dogid)
        {
            
            if (isindog())
                return true;
            if (dogid == "")
                return false;
            else
            {
                if (dogid != getdogid())
                    return false;
                else
                    return true;
            }
        }
        public bool isindog()
        {
            string name = getuname();
            string s = ConfigurationManager.AppSettings["dogusers"];
            if (s != null)
            {
                if (s == "*")
                    return true;
                string[] ss = s.Split(',');
                foreach (string m in ss)
                {
                    if (m == name)
                        return true;
                }
            }
            return false;
        }
        protected override void OnPreLoad(EventArgs e)
        {
            base.OnPreLoad(e);
            if (Session["login"] == null)
            {
                Response.Redirect("~/jump.html", false);
            }
        }
        public int getid()
        {
            int id = 0;
            if (Session["login"] != null)
            {
                DataSet ds = Session["login"] as DataSet;
                //int roles_id = Convert.ToInt32(ds.Tables[0].Rows[0]["roles_id"].ToString());
                id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"].ToString());
            }
            return id;
        }
        public int getaid()
        {
            int aid = 0;
            if (Session["login"] != null)
            {
                DataSet ds = Session["login"] as DataSet;
                if (ds.Tables[0].Rows[0]["user_aid"] != null && ds.Tables[0].Rows[0]["user_aid"].ToString()!="")
                aid = Convert.ToInt32(ds.Tables[0].Rows[0]["user_aid"].ToString());
            }
            return aid;
        }
        public string getdep()
        {
            string dep = "";
            if (Session["login"] != null)
            {
                DataSet ds = Session["login"] as DataSet;
                //int roles_id = Convert.ToInt32(ds.Tables[0].Rows[0]["roles_id"].ToString());
                dep = ds.Tables[0].Rows[0]["depname"].ToString();
            }
            return dep;
        }
        public string getdogid()
        {
            string dep = "";
            if (Session["login"] != null)
            {
                DataSet ds = Session["login"] as DataSet;
                //int roles_id = Convert.ToInt32(ds.Tables[0].Rows[0]["roles_id"].ToString());
                dep = ds.Tables[0].Rows[0]["dogid"].ToString();
            }
            return dep;
        }
        public string getuname()
        {
            string dep = "";
            if (Session["login"] != null)
            {
                DataSet ds = Session["login"] as DataSet;
                //int roles_id = Convert.ToInt32(ds.Tables[0].Rows[0]["roles_id"].ToString());
                dep = ds.Tables[0].Rows[0]["user_login"].ToString();
            }
            return dep;
        }
        public int getroleid()
        {
            int dep = 0;
            if (Session["login"] != null)
            {
                DataSet ds = Session["login"] as DataSet;
                //int roles_id = Convert.ToInt32(ds.Tables[0].Rows[0]["roles_id"].ToString());
                int.TryParse(ds.Tables[0].Rows[0]["roles_id"].ToString(), out dep);
            }
            return dep;
        }
        public int getdepid()
        {
            int dep = 0;
            if (Session["login"] != null)
            {
                DataSet ds = Session["login"] as DataSet;
                //int roles_id = Convert.ToInt32(ds.Tables[0].Rows[0]["roles_id"].ToString());
                int.TryParse(ds.Tables[0].Rows[0]["user_depid"].ToString(), out dep);
            }
            return dep;
        }
        public bool IsLogin()
        {
            bool id =false;
            if (Session["login"] != null)
            {
                id = true;
            }
            return id;
        }
       
    }
}